<template>
    <div>
        <base-list ref="cargoType" :condition="condition" :datas.sync="cargoType" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="100px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="货类名称">
                            <auto-cargo searchName="cargoTypeName" @select="v=>condition['search_LIKE_cargoTypeName']=v"></auto-cargo>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="货类代码">
                            <auto-cargo searchName="cargoTypeCode" @select="v=>condition['search_LIKE_cargoTypeCode']=v"></auto-cargo>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-100">查 询</el-button>
                        <el-button formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WJOB_BASEMGR_MACHINE:ADD')">
                            新增
                        </el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-table slot="list" :data="cargoType" border stripe max-height="550">
                <el-table-column prop="cargoTypeCode" label="货类代码"  min-width="130"></el-table-column>
                <el-table-column prop="cargoTypeName" label="货类名称"  min-width="130"></el-table-column>
                <el-table-column prop="remark" label="备注"  min-width="200"></el-table-column>
                <el-table-column prop="lastModifiedBy" label="最后修改人"  min-width="200"></el-table-column>
                <el-table-column prop="lastModifiedDateTime" label="最后修改时间"  min-width="200"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <!-- v-if="power('WJOB_BASEMGR_MACHINE:UPD')" -->
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)" >
                            编辑
                        </el-button>
                        <!-- v-if="power('WJOB_BASEMGR_MACHINE:DEL')" -->
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <cargo-type-form ref="cargoTypeForm" @load="loadData"></cargo-type-form>
    </div>
</template>

<script>
    import { deleteCargoType, getCargoTypeList } from "@/api/baseResource/baseResource"
    import cargoTypeForm from './cargoTypeForm'
    import autoCargo from '@/components/autocomplete/autoCargo'

    export default {
        name: "cargoType",
        components: {
            cargoTypeForm,
            autoCargo
        },
        data() {
            return {
                condition: {}, // 查询条件
                cargoType: [], // table数组
                pageSearch: getCargoTypeList, // 分页查询api接口
                id: ''
            }
        },
        mounted() {
            this.$nextTick(() => {
                this.loadData()
            })
        },
        methods: {
            loadData() {
                this.$refs.cargoType.loadData()
            },
            handleDialogFormOpen(bool, item) {
                if (bool) {
                    let form = JSON.parse(JSON.stringify(item))
                    this.$refs.cargoTypeForm.form = form
                    this.$refs.cargoTypeForm.isEdit = true
                    this.$refs.cargoTypeForm.dialogForm = true
                } else {
                    this.$refs.cargoTypeForm.dialogForm = true
                }
            },
            handleRemove(item) {
                this.$confirm(`是否删除该数据?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteCargoType(item.id).then(res => {
                        this.$message({
                            type: 'success',
                            message: `删除成功!`
                        });
                        this.loadData()
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            }
        },
    }

</script>

<style scoped>


</style>
